package org.csu.storemanage.controller;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import lombok.NoArgsConstructor;
import org.csu.storemanage.pojo.CartItem;
import org.csu.storemanage.pojo.Order;
import org.csu.storemanage.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class CartController {
    private CartService cartService;


    @Autowired
    CartController(CartService cartService){this.cartService = cartService;}

    @RequestMapping("/orderDetail")
    String showOrder(HttpServletRequest req)
    {
        HttpSession session = req.getSession();
        String username = (String)session.getAttribute("username");
        if(username == null)
        {
            session.setAttribute("errMsg","用户未登录");
            return "login";
        }
        int orderBelong = Integer.parseInt(req.getParameter("orderBelong"));
        System.out.println(orderBelong);
        List<CartItem> cartItemList = cartService.getCartItemListByIOrderBelong(orderBelong);
        req.setAttribute("orderLists",cartItemList);
        req.setAttribute("orderBelong",orderBelong);
        return "orderDetail";
    }
}
